/*
 * Copyright 2010 EES GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.eesgmbh.gimv.samples.googlechartapi.client.linecolors;

import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.ListBox;

/**
 *	Displays a dropdown list of available colors.
 *
 * @author Sascha Hagedorn - EES GmbH - s.hagedorn@ees-gmbh.de
 *
 */
public class ColorListViewImpl implements ColorListPresenter.View {

	private ListBox colorListBox;

	public ColorListViewImpl(ListBox listBox) {

		this.colorListBox = listBox;

		this.colorListBox.addItem("green", "86AC32");
		this.colorListBox.addItem("purple", "836AE6");
		this.colorListBox.addItem("gray", "A6A69B");
		this.colorListBox.setVisibleItemCount(1);
	}

	public void setColor(int index) {
		this.colorListBox.setItemSelected(index, true);
	}

	public void addChangeHandler(ChangeHandler handler) {
		this.colorListBox.addChangeHandler(handler);
	}

	public String getSelectedItem() {
		return this.colorListBox.getValue(this.colorListBox.getSelectedIndex());
	}

}
